<template>
  <div class="viewcontainer" v-if="dataset">
    <hi-toolbar
      :source="dataset"
      v-bind="toolbar"
      style="margin-bottom: 10px"
      :disabled="dataset.isReadonly()"
    ></hi-toolbar>
    <hi-form
      ref="detailForm"
      :model="dataset.curRecord"
      :dataSource="dataset"
      v-bind="form"
      :disabled="dataset.isReadonly()"
    ></hi-form>
  </div>
</template>

<script>
import { HiForm, HiToolbar } from "hi-ui";
import viewBase from "../../base";
import datasetCfg from "./dataset";
import audittag from "@/views/component/audittag";
export default {
  name: "expenditureDetail",
  extends: viewBase,
  components: {
    HiForm,
    HiToolbar,
    audittag,
  },

  data() {
    let dataset = null;
    return {
      //数据集配置
      datasetCfg: datasetCfg,

      //数据集
      dataset: dataset,
      toolbar: {
        buttons: [
          {
            kind: "save",
            //text: "保存",
            type: "danger",
            icon: "el-icon-upload",
          },
          {
            kind: "flow",
            type: "primary",
            text: "审批",
            icon: "el-icon-circle-check",
            click: function () {
              let dataset = this.source;

              let data = dataset.data;
              if (data.length == 0) {
                this.$message({
                  message: "没有找到要审批的数据",
                  type: "warning",
                });
                return;
              }
              if (this.source.getDirty()) {
                this.$message({
                  message: "请先保存数据，再审批",
                  type: "warning",
                });
                return;
              }
              let fnumer = data[0].FNUMBER;

              let toolbar = this;
              this.$confirm(
                `确定审批【${fnumer}】吗?审批后将无法删除和修改!`,
                "提示",
                {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
                }
              )
                .then(() => {
                  for (let i = 0; i < data.length; i++) {
                    let item = data[i];
                    item.FAUDIT = 0;
                  }
                  dataset.save().then((res) => {
                    toolbar.$message({
                      message: `【${fnumer}】审批成功`,
                      type: "success",
                    });
                  });
                })
                .catch(() => {});
            },
          },
        ],
      },
      //数据桥梁
      dataBridge: new Map(),
      //编辑数据
      editData: {},
      //表单配置
      form: {
        columnsTotal: 2,
        labelWidth: "180px",
        items: [
          {
            name: "FNUMBER",
          },
          {
            name: "FEXPENDTYPE",
            element: "hi-select-grid",
            props: {
              selectOption: {
                // remote:true,
                loading: true,
                multiple: false,
                clearable: true,
                filterable: true,
                "allow-create": true,
                "collapse-tags": true,
              },
              lookup: {
                modelFile: "database/base/dataset/BaseEntity.xml",

                param: {
                  FPID: "zclx",
                },
                tableprops: {
                  // border:true,
                  //stripe:true,
                  "show-header": false,
                  //fit:false,
                  size: "mini",
                  "max-height": 400,
                },
                returnFields: {
                  FEXPENDTYPE: "FDESC",
                },
                columns: [
                  {
                    name: "FDESC",
                    label: "支出类型",
                  },
                ],
              },
            },
          },
          {
            name: "FMONEY",
            props: {
              format: "￥0.00",
              precision: 2,
            },
          },
          {
            name: "FNOTE",
            colspan: 2,
            props: {
              type: "textarea",
              autosize: {
                minRows: 4,
                maxRows: 4,
              },
              maxlength: 200,
            },
          },
          {
            name: "FUSERID",
          },
          {
            name: "FCREATEDATE",
          },
          {
            element: audittag,
            name: "FAUDIT",
          },
        ],
      },
    };
  },
  model: {
    prop: "value",
    event: "valuechange",
  },
  props: {
    value: {
      type: Object,
    },
  },

  computed: {},
  watch: {},
  methods: {},
  mounted() {
    this.dataset = this.createDataSet(this.datasetCfg);
    this.dataBridge.set(this.dataset, ["detailForm"]);
    if (this.$route.query.id) {
      this.dataset.load({
        FID: this.$route.query.id,
      });
    } else {
      this.dataset.add({});
    }
    this.flowConfig = { dataset: this.dataset };
    if (this.$route.query.id) {
      this.dataset.load({
        FID: this.$route.query.id,
      });
    }
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scope>
.formtitle {
  margin-top: 15px;
}
</style>
